<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>可交互任务列表</title>
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background: linear-gradient(135deg, #fdfcfb 0%, #e2d1c3 100%);
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            margin: 0;
        }

        #task-container {
            background-color: rgba(255, 255, 255, 0.8);
            padding: 2rem;
            border-radius: 12px;
            box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
            width: 90%;
            max-width: 400px;
        }

        #task-input {
            width: 70%;
            padding: 0.75rem;
            border: 1px solid #ccc;
            border-radius: 6px;
            margin-right: 0.5rem;
            font-size: 1rem;
        }

        #add-task {
            padding: 0.75rem 1.5rem;
            background-color: #4CAF50;
            color: white;
            border: none;
            border-radius: 6px;
            cursor: pointer;
            font-size: 1rem;
            transition: background-color 0.3s ease;
        }

        #add-task:hover {
            background-color: #45a049;
        }

        ul {
            list-style-type: none;
            padding: 0;
            margin-top: 1.5rem;
        }

        li {
            display: flex;
            align-items: center;
            padding: 0.75rem 0;
            border-bottom: 1px solid #e0e0e0;
        }

        li.completed span {
            text-decoration: line-through;
            color: #888;
        }

        input[type="checkbox"] {
            margin-right: 1rem;
        }

        .delete-task {
            margin-left: auto;
            background-color: #f44336;
            color: white;
            border: none;
            border-radius: 6px;
            padding: 0.5rem 1rem;
            cursor: pointer;
            font-size: 0.9rem;
            transition: background-color 0.3s ease;
        }

        .delete-task:hover {
            background-color: #da190b;
        }
    </style>
</head>

<body>
    <div id="task-container">
        <input type="text" id="task-input" placeholder="输入新任务">
        <button id="add-task">添加任务</button>
        <ul id="task-list"></ul>
    </div>
    <script>
        const taskInput = document.getElementById('task-input');
        const addTaskButton = document.getElementById('add-task');
        const taskList = document.getElementById('task-list');

        addTaskButton.addEventListener('click', function () {
            const taskText = taskInput.value.trim();
            if (taskText) {
                const listItem = document.createElement('li');

                const checkbox = document.createElement('input');
                checkbox.type = 'checkbox';
                checkbox.addEventListener('change', function () {
                    if (this.checked) {
                        listItem.classList.add('completed');
                    } else {
                        listItem.classList.remove('completed');
                    }
                });

                const taskSpan = document.createElement('span');
                taskSpan.textContent = taskText;

                const deleteButton = document.createElement('button');
                deleteButton.textContent = '删除';
                deleteButton.classList.add('delete-task');
                deleteButton.addEventListener('click', function () {
                    taskList.removeChild(listItem);
                });

                listItem.appendChild(checkbox);
                listItem.appendChild(taskSpan);
                listItem.appendChild(deleteButton);
                taskList.appendChild(listItem);
                taskInput.value = '';
            }
        });
    </script>
</body>

</html>
    